<?php
//简单管理页面范例，在你的管理页面引用coresection/checkA.php就OK，当然，不要忘了添加注销登录的链接
include_once '../coresection/checkA.php';
?>


<?
if(isset($_REQUEST['sys_part']))
{
    $system_part = $_REQUEST ['sys_part'];
}

if(isset($_REQUEST['nowpageid']))
{
    $nowpageid = $_REQUEST['nowpageid'];
}

if(isset($_REQUEST['sortby']))
{
    $sortby = $_REQUEST['sortby'];
}

if(isset($_REQUEST['term_nid']))
{
    $term_nid = $_REQUEST['term_nid'];
}

?>

<?php

include_once("language.php");//属性名字
?>

<?
include_once("../../config_controller.php");
$host = $_SERVER['HTTP_HOST']; //取得进入所输入的域名
$theme_folder = host_theme($host);

include_once '../../front/' . $theme_folder . '/connection.php';include_once '../coresection/check_session.php';;
?>

<?php include_once ("function.php");?>
<?php include "../../front/".$theme_folder."/config.php" ;?>

<?php include_once ("../coresection/site-function.php");?>


<?php include_once("first_term.php"); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <?php include_once('../modules/head.php'); ?>

    <link href="../css/<?echo $theme_folder?>/user.css" rel="stylesheet" type="text/css"/>

    <script type="text/jscript" src="../js/js.js" ></script>
	<?//js日期控件?>
    <script src="/application/laydate/laydate.js"></script>



    <!--kindeditor编辑器-->
    <link rel="stylesheet" href="../keditor/themes/default/default.css" />
    <script charset="utf-8" src="../keditor/kindeditor-all.js"></script>
    <script charset="utf-8" src="../keditor/lang/zh_CN.js"></script>
    <script>
        var editor;
        KindEditor.ready(function(K) {
            editor = K.create('textarea[name="term_detail"]', {
                allowFileManager : true
            });

        });
    </script>
    <!--kindeditor编辑器-->

    <style>
        .layui-input-block {
            margin-left: 130px;
        }

        .layui-form-label {

            width: 100px;
        }


    </style>
</head>

<body>

<div id="topbar">
    <!--TopBar端點01-->
    <?php include '../modules/topbar.php'; ?>
    <!--TopBar端點02-->
</div>

<div id="container">
    <!--Container端點01-->
    <div id="maincontent"   class="detail">
        <!--maincontent端點01-->

        <div id="sidebar">
            <?php include '../modules/sidebar.php'; ?>
        </div>


        <div id="content">
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                <legend><h1>添加<? echo $sys_title ?> 分类</h1></legend>
            </fieldset>




            <div class="<? echo $system_part ?>">

                <div class="term-detail-boxes layui-form">
                    <ul class="detail-box detail-boxing">
                        <form id="term_detail_form" method="post" action="term-add-function.php?sys_part=<? echo $system_part?>" enctype="multipart/form-data" name="uploadfile" onsubmit="return checkRequired(term_name);" class="  layui-form-pane" >

                            <li class="mid"><label class="layui-form-label">人工编号：</label>
    <div class="layui-input-block"><input type="text" class="layui-input"  name="term_mid" size="20" value=""></div>
                <em class="explain">(填写您自己设置的编号，人工编号不作排序)</em></li>

                            <li class="name">
                                <label class="layui-form-label">分类名称：</label>
    <div class="layui-input-block"><input type="text" class="layui-input"  name="term_name" size="20" value=""></div>
                <em class="explain">(<u style="color:red">*必填项目</u>,填写本分类的标题)</em>
                            </li>

                            <li class="en_name">
                                <label class="layui-form-label">英文分类名称：</label>
                                <div class="layui-input-block"><input type="text" class="layui-input" name="term_en_name" size="20" value=""></div>
                                <em class="explain">(<u style="color:red">*必填项目</u>,填写本分类英文的标题)</em>
                            </li>

                            <li class="search_name">
                                <label class="layui-form-label">关键字：</label>
    							<div class="layui-input-block"><input type="text" class="layui-input"  name="term_search_name" size="20" value=""></div>
                				<em class="explain">(填写多个关键字请用英文逗号区分好   例子 关键1,关键2)</em>
                            </li>

                            <li class="term"><label class="layui-form-label">所属分类：</label>

								<div class="layui-input-block">

                                <select name="term_term_id">


                                    <option value="root" selected="selected">当前所属分类:根目录 \</option>
                                    <?
                                    $table_Suffix = $sys_term_table;
                                    $table = $table_Prefix . $table_Suffix;
                                    $sort_by = "nid";
                                    $sort_order = "desc";
                                    ?>

                                    <?php
                                    $query = mysql_query("SELECT COUNT(nid) FROM $table where interm = 'root' and belong ='$sys_belong'");
                                    $term0sum = mysql_result($query, 0);

                                    $result_term0 = mysql_query("select * from $table where interm='root' and belong = '$sys_belong' ORDER BY $sort_by $sort_order");

                                    while($row = mysql_fetch_array($result_term0))
                                    {
                                        $term0_nid[]=$row['nid'];
                                        $term0_name[]=$row['name'];
                                    }

                                    ?>
                                    <? for($i=0;$i<$term0sum;$i++) { ?>
                                        <option value="<?php echo $term0_nid[$i] ?>"> | - <?php echo $term0_name[$i] ?></option>
                                        <?
                                        $query2 = mysql_query("SELECT COUNT(nid) FROM $table where term1 = $term0_nid[$i] && interm = 'term1'  and belong ='$sys_belong'  ");
                                        $term1sum = mysql_result($query2, 0);
                                        if ($_REQUEST ['sortby']) {
                                            $sort_by = $_REQUEST ['sortby'];
                                        }
                                        $result1 = mysql_query("select * from $table where term1 = $term0_nid[$i] && interm = 'term1' and belong ='$sys_belong'  ORDER BY $sort_by ");
                                        while ($row = mysql_fetch_array($result1)) {
                                            {
                                                $term1_nid[$i][] = $row['nid'];
                                                $term1_mid[$i][] = $row['mid'];
                                                $term1_name[$i][] = $row['name'];
                                            }
                                        }
                                        ?>
                                        <?for ($ii = 0; $ii < $term1sum; $ii++) {?>
                                            <option value="<?php echo $term1_nid[$i][$ii] ?>"> |---- <?php echo $term1_name[$i][$ii] ?></option>
                                        <?php } ?>
                                    <?php } ?>


                                </select></div>
                <em class="explain">(选择本分类对应的上级分类，如是一级分类，请选择“根目录”)</em></li>
                            <li  class="introduce"><label class="layui-form-label">分类简介：</label>
                            	<div class="layui-input-block">
                                <textarea name="term_introduce" cols="20"></textarea></div>
                <em class="explain">(填写本分类的分类概述文字)</em>
                            </li>

                            <li class="icon"><label class="layui-form-label">ICON：</label><img src="../images/default-image.jpg" width="150"/><span class="title-data">(请上传像素<? echo $first_icon_data[0]?>X<? echo $first_icon_data[1]?>符合比例的图片,格式为jpeg)</span></li>
                            <li class="icon"><label class="layui-form-label">上传文件：</label>
    <div class="layui-input-block"><input type="file" name="icon"  onchange="fileChange(this);"/></div>
                <em class="explain">(上传本分类的列表图标)</em></li>
                            <br />


                            <li class="banner"><label class="layui-form-label">横幅图片：</label><img src="../images/default-image.jpg" width="150"/><span class="title-data">(请上传像素<? echo $first_banner_data[0]?>X<? echo $first_banner_data[1]?>符合比例的图片,格式为jpeg)</span></li>
                            <li class="banner"><label class="layui-form-label">上传文件：</label>
    <div class="layui-input-block"><input type="file" name="upfile1"  onchange="fileChange(this);"/></div>
                <em class="explain">(上传本分类的横幅Banner图片)</em></li>

                            <li class="banner"><label class="layui-form-label">横幅标题：</label>
    <div class="layui-input-block"><input type="text" class="layui-input"  name="term_banner_title"value=""></div>
                <em class="explain">(填写横幅标题内容)</em></li>

                             <li class="banner"><label class="layui-form-label">横幅链接：</label>
    <div class="layui-input-block"><input type="text" class="layui-input"  name="term_banner_url"value=""></div>
                <em class="explain">(填写横幅链接内容)</em></li>

                            <li class="extend_img"><label class="layui-form-label"><?php echo $$term_extend_name ? $$term_extend_name : '备用'?>图片：</label><img src="../images/default-image.jpg" width="150"/><span class="title-data">(请上传像素<? echo $first_extend_img_data[0]?>X<? echo $first_extend_img_data[1]?>符合比例的图片,格式为jpeg)</span></li>
                            <li class="extend_img"><label class="layui-form-label">上传文件：</label>
    <div class="layui-input-block"><input type="file" name="upfile2"  onchange="fileChange(this);"/></div>
                <em class="explain">(上传本分类的<?php echo $$term_extend_name ? $$term_extend_name : '备用'?>图片)</em></li>
                            <br />


                            <li class="title"><label class="layui-form-label">网页用标题：</label>
    <div class="layui-input-block"><input type="text" class="layui-input"  name="term_title" size="20" value=""></div>
                <em class="explain">(填写浏览器标签页显示的本分类页名称)</em></li>
                            <li class="description"><label class="layui-form-label">网页用描述：</label><div class="layui-input-block"><textarea name="term_description"></textarea></div>
                <em class="explain">(填写本分类页描述性文字，用于搜索引擎的搜索结果显示)</em></li>
                            <li class="keyword"><label class="layui-form-label">网页用关键词：</label><div class="layui-input-block"><textarea name="term_keyword"></textarea></div>
                <em class="explain">(填写本分类页的关键词，利于搜索引擎抓取)</em></li>
                            <li class="url"><label class="layui-form-label">网页地址：</label>
    <div class="layui-input-block"><input type="text" class="layui-input"  name="term_url" size="20" value="T<? echo get_max_nid("term") ?>"></div>
                <em class="explain">(填写本分类页前台网址，用于伪静态设置，利于搜索引擎抓取)</em></li>
                            <br />



                            <li class="detail">
                                <label class="layui-form-label">分类详情：</label>
                                <div class="layui-input-block"><textarea name="term_detail" style="width:800px;height:400px;visibility:hidden;">
                                </textarea></div>
                <em class="explain">(填写本分类前台显示的详细文字介绍，默认留空)</em>
                            </li>



                            <li class="listorder"><label class="layui-form-label">列表排序：</label>
    <div class="layui-input-block"><input type="text" class="layui-input"  name="term_listorder" size="20" value="0" onkeydown="onlyNum();" onfocus="checkdefault(term_listorder)" onblur="checkempty(term_listorder)"></div>
                <em class="explain">(填写本分类在所属前台列表下的列表排序，数字越大，排序越靠前)</em></li>

                            <li class="hotsale"><label class="layui-form-label">热销分类：</label>


                                <div class="layui-input-block">
                                    <input name='term_hotsale' type='radio' value='1' id='hotsale_now' title="标记热销" />
                                    <input name='term_hotsale' type='radio' value='0' id='hotsale_later' checked='checked' title="取消热销" />

                                </div>
                				<em class="explain">(可标记热销分类，将在前台添加热销分类标识或显示热销产品分类)</em>

                            </li>

                            <li class="recommend"><label class="layui-form-label">推荐分类：</label>
                                <div class="layui-input-block">
                                    <input name='term_recommend' type='radio' value='1' id='recommend_now' title="确认推荐"/>

   									<input name='term_recommend' type='radio' value='0' id='recommend_later' checked='checked' title="取消推荐" />

                                </div>
                <em class="explain">(可标记推荐分类，将在前台添加推荐分类标识或显示推荐产品分类)</em>
                            </li>

                            <li class="publish"><label class="layui-form-label">发布状态：</label>
                                <div class="layui-input-block">
                                    <input name='term_publish' type='radio' value='1' id="publish_now" title="立即发布"/>

    								<input name='term_publish' type='radio' value='0' id="publish_later"  checked="checked" title="暂未发布"  />

                                </div>
                <em class="explain">(选择立即发布，以上信息才能在前台显示；选择暂未发布，只对以上信息进行保存，不在前台显示)</em>
                            </li>

                            <li class="mark"><label class="layui-form-label">标记产品：</label>


                                <div class="layui-input-block">
                                    <input name='term_mark' type='radio' value='1' id='mark_now'  title="添加标记"/>

    								<input name='term_mark' type='radio' value='0' id='mark_later' checked='checked' title="取消标记"  />

                                </div>
                <em class="explain">(选择添加标记，以上信息将在前台显示；选择取消标记，以上信息不在前台显示)</em>

                            </li>

                            <li class="vip"><label class="layui-form-label">权限设置：</label>
                                <div class="layui-input-block">
                                    <input name='term_vip' type='radio' value='0' id='vip_now' checked='checked' title="游客可见"/>

   									<input name='term_vip' type='radio' value='1' id='vip_one' title="vip1可见"/>

    								<input name='term_vip' type='radio' value='2' id='vip_two' title="vip2可见"/>

                                </div>
                <em class="explain">(设置会员可浏览的权限)</em>
                            </li>




                            <li class="markorder"><label class="layui-form-label">标记排序：</label>
    <div class="layui-input-block"><input type="text" class="layui-input"  name="term_markorder" size="20" value="0" onkeydown="onlyNum();" onfocus="checkdefault(term_markorder)" onblur="checkempty(term_markorder)"></div>
                <em class="explain">(填写分类在前台列表中的排序，数字越大，排序越靠前)</em></li>


                            <li class="link"><label class="layui-form-label">链接地址：</label>
    <div class="layui-input-block"><input type="text" class="layui-input"  name="term_link" size="20" value=""></div>
                <em class="explain">(填写用于前台直接跳转的文章链接，类似于转载文章，默认留空)</em></li>
                            <li class="clickrate"><label class="layui-form-label">点击次数：</label>
    <div class="layui-input-block"><input type="text" class="layui-input"  name="term_clickrate" size="20" value="0" onkeydown="onlyNum();" onfocus="checkdefault(term_clickrate)" onblur="checkempty(term_clickrate)"></div>
                <em class="explain">(显示此分类在前台被浏览点击的次数，亦可在由后台管理员自行设置数量)</em></li>

                            <li class="inputtime"><label class="layui-form-label">输入时间：</label>
    <div class="layui-input-block"><input type="text" class="layui-input"  name="term_inputtime" size="20" value="<? echo date("Y-m-d H:i:s") ?>" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})" class="laydate-icon"></div>
                <em class="explain">(填写分类录入时间)</em></li>

							 <li class="layui-form-item is_disabled">
                                <label class="layui-form-label">禁止删除：</label>

                                <div class="layui-input-block">
                                        <input name='term_is_disabled' type='radio' value='1'  title="禁止删除" />
                                        <input name='term_is_disabled' type='radio' value='0'  title="允许删除" />
                                    </div>
                <em class="explain">(如标记了禁止删除，列表页下面不能删除当前信息)</em>
                        
                             </li>  
				
                <div class="more_link" style="display:none;" >
                	<?php 
					$brand_list = select_lines_all_items($table_Prefix . "term", ' nid  desc ' , " belong = 'brand' "); 
					
					foreach($brand_list as $key=>$val){
						$new_brand_list[$val['nid']]['title'] = $val['name'];
						$new_brand_list[$val['nid']]['value'] = $val['nid'];
					}
					$json_brand_list = json_encode($new_brand_list);
					
					?>
                    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;" id="content4">
                        <legend>关联品牌</legend>
                    </fieldset>
                    <br/>
                
                
                    <div style="position:relative;">
                    	<div id="test4" class="demo-transfer"></div>
						 	<div class="buttonDiv">
                            <button type="button" class="layui-btn layui-btnUpDownmax upMaxBtn" onclick="moveUpMax('test4')"> 
                                <i class="layui-icon">&#xe619;</i>
                                <i class="layui-icon">&#xe619;</i>
                            </button>
                            <button type="button" class="layui-btn layui-btnUpDown upBtn" onclick="moveUp('test4')"> 
                                <i class="layui-icon">&#xe619;</i>
                            </button>
                            <button type="button" class="layui-btn layui-btnUpDown downBtn" onclick="moveDown('test4')">
                                <i class="layui-icon">&#xe61a;</i>
                            </button>
                            <button type="button" class="layui-btn layui-btnUpDownmax downMaxBtn" onclick="moveDownMax('test4')">
                                <i class="layui-icon">&#xe61a;</i>
                                <i class="layui-icon">&#xe61a;</i>
                            </button>
                            
                        </div>
                    	</div>
                	</div>
	 			<hr/>
                            <div class="function">
                               	<input type="hidden" name="detail_attr" id="detail_attr" />
                                <button class="layui-btn "  type="button" lay-submit lay-filter="formSub">立即提交</button>
                                <input type="reset" class="layui-btn" value="重置"/>
                            </div>
                        </form>
                    </ul>
                </div>
            </div>

            <!--content端點01-->
        </div>
        <!--maincontent端點01-->
        <br class="clearfloat" />
    </div>
    <!--container端點01-->
</div>



<?php include ROOT_PATH_ . "/controller/modules/footer.php"; ?>
<script type="text/javascript">
layui.use(['transfer', 'layer', 'util', 'form'], function(){
	  var $ = layui.$
	  ,transfer = layui.transfer
	  ,layer = layui.layer
	  ,util = layui.util
	  ,form = layui.form;


	var data1 = []  //显示搜索框
	transfer.render({
			elem: '#test4'
			,data: <?php echo $json_brand_list;?>
			,title: ['全选', '全选']
			,showSearch: true
			,height:300
			,width:600
			,id: 'detail_attr_list'
	}) 
						
						
	  form.on('submit(formSub)', function(data){
		 
		  
		   var ul = $("#test4").find("ul").eq(1);
			var input = $(ul).find("input");
			var saveArr = [];
			for(var i = 0; i < input.length; i++) {
				var inJson = {};
				
				inJson["title"] = input[i].title;
				inJson["value"] = input[i].value;
				saveArr.push(inJson);
			}
			json_data= JSON.stringify(saveArr)
		  
		  $('#detail_attr').val(json_data)
		  
		  	window.editor.sync();
			$('.layui-form-pane').submit() 	
		 
	  })
	  
	});
	
	
//上移
		function moveUp(dom) {
			//找到选中的li
			var index = $("#"+dom+" ul" ).eq(1).find('.layui-form-checked').parent(); 
			if(typeof(index[0]) == "undefined") {
				layer.msg("请选中后，再进行移位操作");
				return;
			}
			for(var i=0;i<index.length;i++){
				if(index.eq(i).index()!=0){
					 index.eq(i).prev().before(index.eq(i));
				}
			}   
					
		}
		
		//置顶
		function moveUpMax(dom) {
			//找到选中的li
			var index = $("#"+dom+" ul" ).eq(1).find('.layui-form-checked').parent(); 
			if(typeof(index[0]) == "undefined") {
				layer.msg("请选中后，再进行移位操作");
				return;
			}
			for(var i=index.length-1;i>=0;i--){
				do{
					index.eq(i).prev().before(index.eq(i));
				}while(index.eq(i).index()!=0)
			}       			
		}
		
		//下移
		function moveDown(dom) {
			//找到选中的li
			var index = $("#"+dom+" ul" ).eq(1).find('.layui-form-checked').parent(); 
			if(typeof(index[0]) == "undefined") {
				layer.msg("请选中后，再进行移位操作");
				return;
			}
			for(var i=index.length-1;i>=0;i--){
				if(index.eq(i).index()!=($("#"+dom+" ul li").length-1)){
					 index.eq(i).next().after(index.eq(i));
				}
			}       			
		}
		
		//置底
		function moveDownMax(dom) {
			//找到选中的li
			var index = $("#"+dom+" ul" ).eq(1).find('.layui-form-checked').parent(); 
			if(typeof(index[0]) == "undefined") {
				layer.msg("请选中后，再进行移位操作");
				return;
			}
			for(var i=0;i<index.length;i++){
				do{
					index.eq(i).next().after(index.eq(i));
				}while(index.eq(i).index()!=($("#"+dom+" ul").eq(1).find("li").length-1))
			}       			
		}


</script>
</body>
</html>
